import requests
from util.timestamp import get_timestamp
import execjs
from hashlib import md5
import os
os.environ["PYTHONIOENCODING"] = "utf-8"

page = 2


with open('./parse/福建公共交易平台.js',encoding='utf8') as f:
    js_str = f.read()
    js_code = execjs.compile(js_str,'./parse')

e = {
    "ts": get_timestamp(),
    "pageNo": page,
    "pageSize": 20,
    "total": 3409,
    "AREACODE": "",
    "M_PROJECT_TYPE": "",
    "KIND": "GCJS",
    "GGTYPE": "1",
    "PROTYPE": "",
    "timeType": "6",
    "BeginTime": "2025-05-20 00:00:00",
    "EndTime": "2025-11-20 23:59:59",
    "createTime": ""
}

n = js_code.call('d',e)
sign = md5(n.encode('utf-8')).hexdigest()

print(sign)

res = requests.post('https://ggzyfw.fujian.gov.cn/FwPortalApi/Trade/TradeInfo',
                    json=e,
                    headers={
                        'portal-sign':sign
                    })

data = res.json()['Data']
# print(data)
r = js_code.call('b',data)
print(r)

